#pragma once

#include "IImage.h"
#include "rect2d.h"

namespace sol9
{
namespace graphics
{

	class Image : public IImage
	{
		__declareClass(Image);

	private:
		u8* m_pData;
		core::dimension2du m_nSize;
		eColorFormat m_eFormat;
		u32 m_nBytesPerPixel;
		u32 m_nPitch;
		bool m_bShared;
		bool m_bLocked;

	public:
		Image(eColorFormat eFormat, const core::dimension2du& nSize);
		Image(eColorFormat eFormat, const core::dimension2du& nSize, void* pData, bool bCopy = true);
		~Image();

		virtual void* lock();
		virtual void unlock();

		virtual void blit(IImage* pOther, const core::position2di& Position = core::position2di(0), eBlitOption eOption = EBO_ImageCopy);
		virtual void fill(const color& cColor);

		virtual color getPixel(u32 x, u32 y) const;
		virtual void setPixel(u32 x, u32 y, const color& c);

		virtual const core::dimension2du& getDimension() const;
		virtual u32 getBitsPerPixel() const;
		virtual u32 getBytesPerPixel() const;
		virtual u32 getSizeInBytes() const;
		virtual u32 getSizeInPixels() const;
		virtual eColorFormat getColorFormat() const;

	private:
		bool _initialize();
		void _blitImage(IImage* pOther, const core::position2di& Position);
		void _blendImage(IImage* pOther, const core::position2di& Position);
		core::rect2di _clipImage(IImage* pOther, const core::position2di& Position);
	};

} // namespace graphics
} // namespace sol9